package com.example.disinfestation.controller;


import com.example.disinfestation.entity.Pest;
import com.example.disinfestation.service.PestService;
import com.example.disinfestation.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("pest")
public class PestController extends BaseController {

    @Autowired
    PestService pestService;



    @RequestMapping("selectAll")
    @ResponseBody
    public JsonResult<List<Pest>> selectAll(){
        JsonResult result = new JsonResult();
        try {
            List<Pest> data = pestService.selectAll();
            System.err.println("查询所有的危害普及");
            result.setState(SUCCESS);
            result.setData(data);
        }catch (Exception e){
            result.setMessage("出现异常");
        }
        return result;
    }



    @RequestMapping("selectById")
    @ResponseBody
    public JsonResult<Pest> selectById(Integer id){
        JsonResult result = new JsonResult();
        System.out.println("根据id查询详情");
        try {
            Pest data = pestService.selectById(id);
            result.setState(SUCCESS);
            result.setData(data);
        }catch (Exception e){
            result.setMessage("出现异常");
        }
        return result;
    }








}
